package ace.cmp.data.methodname.sql.mybatisplus.autoconfig;

import ace.cmp.data.methodname.sql.mybatisplus.autoconfig.properties.MybatisPlugMethodNameToSqlPropertiesConfig;
import ace.cmp.data.methodname.sql.mybatisplus.core.inject.MethodNameToSqlInject;
import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author caspar
 * @date 2023/2/14 11:46
 */
@RequiredArgsConstructor
@EnableConfigurationProperties({MybatisPlugMethodNameToSqlPropertiesConfig.class})
@Configuration
public class MethodNameToSqlMybatisPlusBootstrapAutoConfig {
  private final MybatisPlugMethodNameToSqlPropertiesConfig propertiesConfig;

  @ConditionalOnMissingBean
  @Bean
  public AbstractSqlInjector methodNameToSqlInject() {
    return new MethodNameToSqlInject(
        new DefaultSqlInjector(), propertiesConfig.getMethodNameToSql());
  }
}
